/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.create;

import br.com.deployment.daoImpl.NotaryOfficeDAOImpl;
import br.com.deployment.entities.Address;
import br.com.deployment.entities.NotaryOffice;
import br.com.deployment.enums.TypeAdmission;
import br.com.deployment.utils.Caracter;
import br.com.deployment.utils.Msg;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author ely
 */
@ManagedBean
@SessionScoped
public class ManagerCreateNotaryOffice {

    @EJB
    NotaryOfficeDAOImpl notaryService;
    
    // Objeto criar Cartório
    private NotaryOffice notaryOffice;
    
    // Objeto Endereço 
    private Address addres;
    
     TypeAdmission admission[] = TypeAdmission.values();

    public ManagerCreateNotaryOffice() {
    }

    @PostConstruct
    public void init() {
        notaryOffice = new NotaryOffice();
        addres = new Address();
    }
    
    // Reinicia os Objetos
    public void reinit() {
        notaryOffice = new NotaryOffice();
        addres = new Address();
    }

    // Método para salvar o Cartório
    public void save() {
        System.err.println("Salvando");
        addres.setCellular(Caracter.removecaracter(addres.getCellular()));
        addres.setCep(Caracter.removecaracter(addres.getCep()));
        addres.setPhone(Caracter.removecaracter(addres.getPhone()));
        notaryOffice.setAddress(addres);
        notaryService.save(notaryOffice);
        Msg.messagemInfo("Cartório Salvo");
        reinit();
    }

    // Auto complemento para o Objeto Cartório (Componente Auto Complete)
    public List<NotaryOffice> completeNotary(String query) {
        List<NotaryOffice> bd = new ArrayList<NotaryOffice>();

        NotaryOffice n = new NotaryOffice();
        n.setNome(query);
        bd = notaryService.autoCompleteNotaryOffice(n);
        return bd;
    }

    public NotaryOffice getNotaryOffice() {
        return notaryOffice;
    }

    public void setNotaryOffice(NotaryOffice notaryOffice) {
        this.notaryOffice = notaryOffice;
    }

    public Address getAddres() {
        return addres;
    }

    public void setAddres(Address addres) {
        this.addres = addres;
    }

    public TypeAdmission[] getAdmission() {
        return admission;
    }

    public void setAdmission(TypeAdmission[] admission) {
        this.admission = admission;
    }
    
    
    
}
